//#include <string.h>
//#include <arpa/inet.h>
//#include <sys/ioctl.h>
//#include <net/if.h>
//#include <unistd.h>
//#include <stdio.h>

//#include <sys/time.h>

#include "util.h"

#ifndef USE_LINUX
#include <stdint.h> // portable: uint64_t   MSVC: __int64
#include <Windows.h>
int gettimeofday(struct timeval * tp, struct timezone * tzp) {
    // Note: some broken versions only have 8 trailing zero's, the correct epoch has 9 trailing zero's
    // This magic number is the number of 100 nanosecond intervals since January 1, 1601 (UTC)
    // until 00:00:00 January 1, 1970
    static const uint64_t EPOCH = ((uint64_t) 116444736000000000ULL);

    SYSTEMTIME  system_time;
    FILETIME    file_time;
    uint64_t    time;

    GetSystemTime( &system_time );
    SystemTimeToFileTime( &system_time, &file_time );
    time =  ((uint64_t)file_time.dwLowDateTime )      ;
    time += ((uint64_t)file_time.dwHighDateTime) << 32;

    tp->tv_sec  = (long) ((time - EPOCH) / 10000000L);
    tp->tv_usec = (long) (system_time.wMilliseconds * 1000);
    return 0;
}
#else
#include <sys/time.h>
#include <time.h>
#endif

double getMsecOfNow()
{
    struct timeval tim;
    gettimeofday(&tim, NULL);
    return 1000.0 * tim.tv_sec + (tim.tv_usec / 1000.0);
}

/*
void getMacAddress(char *mac_local)
{
    int fd;
    struct ifreq ifr;
    char iface[5] = "eth0";

    fd = socket(AF_INET, SOCK_STREAM, 0);
    //ifr.ifr_addr.sa_family = AF_INET;
    strncpy((char *)ifr.ifr_name , iface , IFNAMSIZ-1);
    ioctl(fd, SIOCGIFHWADDR, &ifr);
    close(fd);
    unsigned char *mac = (unsigned char *)ifr.ifr_hwaddr.sa_data;
    sprintf(mac_local, "%.2x%.2x%.2x%.2x%.2x%.2x" , mac[0], mac[1], mac[2], mac[3], mac[4], mac[5]);
}
*/
